package com.cn.hotel.servlet.front.serviceItems;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.RoomModel;
import com.cn.hotel.service.IRoomService;
import com.cn.hotel.service.impl.RoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/getPhoto")
public class ServiceItemsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String aa = req.getParameter("id");
        String page = req.getParameter("page");
        Integer temp = aa==null||"".equals(aa)?0:Integer.parseInt(aa);
        Integer pageNumber = page==null||"".equals(page)?1:Integer.parseInt(page);
        Map<String,Integer> map = new HashMap<>();
        map.put("temp",temp);
        map.put("pageNumber",pageNumber);
        IRoomService iRoomService = new RoomServiceImpl();
        List<RoomModel> list = iRoomService.getAppointRoomModel(map);
        int number = iRoomService.getTotal(temp);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("number",number);
        resp.getWriter().println(jsonObject);
    }
}
